package collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

class Book{
    private String name;
    private int value;

    public Book(String name, int value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", value=" + value +
                '}';
    }
}

public class IteratorShow {
    public static void main(String[] args) {
        Collection<Object> col = new ArrayList<>();
        col.add(new Book("1", 1));
        col.add(new Book("2", 2));
        col.add(new Book("3", 3));

        //迭代器注意重置
        Iterator<Object> iterator = col.iterator();
        while(iterator.hasNext()){
            Object next = iterator.next();
            System.out.println(next);
        }

        for (Object o : col) {
            System.out.println(o);
        }

    }
}
